package com.demo.aop.pcut.annotation;

import com.demo.aop.pcut.stat.SimpleAdvice;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

/**
 * 描述：
 *
 * @author lida
 * @time 2019/10/26 11:22
 */
public class AnnotationPointcutDemo {

	public static void main(String[] args) {
		Guitarist guitarist = new Guitarist();

		AnnotationMatchingPointcut pointcut = AnnotationMatchingPointcut.forMethodAnnotation(AdviceRequired.class);
		Advisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleAdvice());

		ProxyFactory pf = new ProxyFactory();
		pf.addAdvisor(advisor);
		pf.setTarget(guitarist);

		Guitarist proxy = (Guitarist) pf.getProxy();
		proxy.sing();
		proxy.sing("哈哈");

	}
}
